import { request } from '../utils/request';
import type { FinanceData, FinanceQuery, FinanceAnalysisData } from '../types/finance';
import type { ApiResponse } from '../types/common';

export const financeApi = {
  // 获取企业财务数据
  getFinanceData: (enterpriseId: string) => 
    request.get<ApiResponse<FinanceData>>(`/api/enterprises/${enterpriseId}/finance`),

  // 获取财务分析数据
  getFinanceAnalysis: (params: FinanceQuery) => 
    request.get<ApiResponse<FinanceAnalysisData>>('/api/finance/analysis', { params }),

  // 导出财务报表
  exportFinanceReport: (enterpriseId: string, year?: string) => 
    request.get(`/api/enterprises/${enterpriseId}/finance/export`, {
      params: { year },
      responseType: 'blob',
    }),

  // 导入财务数据
  importFinanceData: (enterpriseId: string, file: File) => {
    const formData = new FormData();
    formData.append('file', file);
    return request.post(`/api/enterprises/${enterpriseId}/finance/import`, formData, {
      headers: { 'Content-Type': 'multipart/form-data' },
    });
  },
}; 